package com.btex.app.treaty.list;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.TreatyEntrustInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/16
 * @time 下午12:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class EntrustListAdapter extends BaseQuickAdapter<TreatyEntrustInfo.DataBean.OrderListsBean, BaseViewHolder> {
    private String mIsZhen;
    private String mDanwei = "";
    private String mIsreverse;
    private String mNumbers = "8";
    private String mPriceNumber = "2";
    private String mDanValue = "1";

    public EntrustListAdapter(@Nullable List<TreatyEntrustInfo.DataBean.OrderListsBean> data) {
        super(R.layout.fragment_entrust_list, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TreatyEntrustInfo.DataBean.OrderListsBean item) {

//        名字
        TextView item_treaty_tv_entrust_name = (TextView) helper.getView(R.id.item_treaty_tv_entrust_name);
//        取消
        TextView item_treaty_tv_entrust_diss = (TextView) helper.getView(R.id.item_treaty_tv_entrust_diss);
//        类型
        TextView item_treaty_tv_entrust_type = (TextView) helper.getView(R.id.item_treaty_tv_entrust_type);
//        已成交数量
        TextView item_treaty_tv_entrust_number = (TextView) helper.getView(R.id.item_treaty_tv_entrust_number);
//        委托价格
        TextView item_treaty_tv_entrust_price = (TextView) helper.getView(R.id.item_treaty_tv_entrust_price);
//        时间
        TextView item_treaty_tv_entrust_time = (TextView) helper.getView(R.id.item_treaty_tv_entrust_time);
        TextView item_treaty_tv_entrust_chengjiao_junjia = (TextView) helper.getView(R.id.item_treaty_tv_entrust_chengjiao_junjia);
        TextView item_treaty_tv_entrust_chengjiao_price = (TextView) helper.getView(R.id.item_treaty_tv_entrust_chengjiao_price);
        TextView item_treaty_tv_entrust_duokong = (TextView) helper.getView(R.id.item_treaty_tv_entrust_duokong);
        TextView item_treaty_tv_entrust_ganggan = (TextView) helper.getView(R.id.item_treaty_tv_entrust_ganggan);
        TextView fragment_entrust_baocang = (TextView) helper.getView(R.id.fragment_entrust_baocang);


        String is_liquidation = item.getIs_liquidation();

        if (is_liquidation.equals("1")) {
            fragment_entrust_baocang.setVisibility(View.VISIBLE);
        }

        item_treaty_tv_entrust_ganggan.setVisibility(View.VISIBLE);
        item_treaty_tv_entrust_duokong.setVisibility(View.VISIBLE);
        item_treaty_tv_entrust_name.setText(item.getSymbol());

        String is_cross = item.getIs_cross();
        if ("1".equals(is_cross)) {
//            item_treaty_tv_entrust_ganggan.setText("(" + mContext.getString(R.string.heyue_quancang) + ")");
            item_treaty_tv_entrust_ganggan.setText("(" + mContext.getString(R.string.heyue_quancang) + item.getLeverage() + ")");
        } else {
            item_treaty_tv_entrust_ganggan.setText("(" + mContext.getString(R.string.zhucang) + item.getLeverage() + "X" + ")");
        }


        View view = helper.getView(R.id.item_entrust_view_type);
        item_treaty_tv_entrust_chengjiao_junjia.setText(R.string.heyue_weituo_jiazhi);

//        item_treaty_tv_entrust_chengjiao_price.setVisibility(View.INVISIBLE);
        String amount = item.getAmount();
        String price = item.getPrice();


        if (!TextUtils.isEmpty(mIsZhen)) {
            if (mIsZhen.equals("1")) {

                if (Double.valueOf(item.getPrice()) == 0) {
                    item_treaty_tv_entrust_chengjiao_price.setText("---" + mDanwei);


                } else {

//                    double v = Double.valueOf(amount) / Double.valueOf(price);
                    double v = Double.valueOf(amount) / Double.valueOf(price) * Double.valueOf(mDanValue);
                    String trim = Tools.round(v, Integer.valueOf(mNumbers)).toString().trim();
                    item_treaty_tv_entrust_chengjiao_price.setText(trim + "\t" + mDanwei);

                }

            } else {

                if (Double.valueOf(item.getPrice()) == 0) {
                    item_treaty_tv_entrust_chengjiao_price.setText("---" + mDanwei);

                } else {
                    double v = Double.valueOf(amount) * Double.valueOf(price) * Double.valueOf(mDanValue);
                    String trim = Tools.round(v, Integer.valueOf(mNumbers)).toString().trim();
                    item_treaty_tv_entrust_chengjiao_price.setText(trim + "\t" + mDanwei);
                }

            }

        }


        helper.addOnClickListener(R.id.item_treaty_tv_entrust_diss);
        String direction = item.getDirection();
        String type = item.getType();
        if ("1".equals(direction)) {
            item_treaty_tv_entrust_duokong.setText(R.string.heyue_duo);
//            item_treaty_tv_entrust_duokong.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
            item_treaty_tv_entrust_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
            view.setBackgroundResource(R.color.bg_green);
            if ("limit".equals(type)) {
                item_treaty_tv_entrust_type.setText(R.string.heyue_xianjia);
            } else {
                item_treaty_tv_entrust_type.setText(R.string.heyue_shijia);
            }

        } else {
            item_treaty_tv_entrust_duokong.setText(R.string.heyue_kong);
//            item_treaty_tv_entrust_duokong.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
            item_treaty_tv_entrust_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
            view.setBackgroundResource(R.color.red);
            if ("limit".equals(type)) {
                item_treaty_tv_entrust_type.setText(R.string.heyue_xianjia);
            } else {
                item_treaty_tv_entrust_type.setText(R.string.heyue_shijia);
            }
        }


        if (Double.valueOf(item.getPrice()) == 0) {
            item_treaty_tv_entrust_price.setText(R.string.heyue_shijia);
        } else {
            String trim = Tools.round(Double.valueOf(item.getPrice()), Integer.valueOf(mPriceNumber)).toString().trim();
            item_treaty_tv_entrust_price.setText(trim);
        }


        String rest_num = item.getRest_num();
        int i = Integer.valueOf(amount) - Integer.valueOf(rest_num);
        item_treaty_tv_entrust_number.setText(amount + "/" + String.valueOf(i));

        String times = Tools.timedate(String.valueOf(item.getCtime()));

        item_treaty_tv_entrust_time.setText(times);

    }

    public void SetIsZhen(String isZhen) {

        mIsZhen = isZhen;
    }

    public void setDanwei(String danwei) {

        this.mDanwei = danwei;
    }


    public void setIsreverse(String Isreverse) {

        mIsreverse = Isreverse;
    }


    public void setNumber(String numbers) {

        mNumbers = numbers;
    }

    public void setPriceNumber(String PriceNumber) {

        mPriceNumber = PriceNumber;
    }

    public void setDanValue(String DanValue) {

        mDanValue = DanValue;
    }

}
